<template>
  <div>
    <mt-header title="订单列表" fixed>
      <router-link to="/" slot="left">
        <mt-button icon="back">返回</mt-button>
      </router-link>
    </mt-header>
    <div class="list">
      <mt-loadmore :bottom-method="loadMore" :bottom-all-loaded="allLoaded" :auto-fill="isAutoFill" ref="loadmore">
        <ul>
          <li v-for="(item, index) in orderList" :key="index" @click="toDetail(item.id)">
            <div class="top">
              <div class="avatar">
                <img :src="item.user.profilePhotoPath" alt="头像" width="35px">
                <p style="float: right; margin-left: 8px;">{{item.user.nickname}}</p>
              </div>
              <div class="time">
                <p>{{ item.gmtCreate | format }}</p>
                <p>{{item.status === 1 ? '未付款' : '已付款'}}</p>
              </div>
            </div>
            <div class="goods">
              <img v-for="(img, index) in item.itemImagePathJson" :key="index" :src="'https://hycos-1257620396.file.myqcloud.com' + img" alt="图片" width="50px">
            </div>
            <div class="bottom">
              共 {{item.itemQuantityTotal}} 种商品，总价 {{ item.orderActualPayment / 100 }}￥
            </div>
          </li>
          <li v-if="allLoaded" class="last">
            --已加载全部--
          </li>
        </ul>
      </mt-loadmore>
    </div>
  </div>
</template>

<script>
export default {
  name: 'order',
  data () {
    return {
      url: {
        list: '/distributor/order/list'
      },
      allLoaded: false,
      isAutoFill: false,
      orderList: [],
      pageNum: 1
    }
  },
  methods: {
    loadMore () {
      this.$ajax.post(this.url.list, {pageNum: this.pageNum++, pageSize: 15}).then(res => {
        if (res.data.success) {
          let user = []
          res.data.data.userList.forEach(item => {
            user['U' + item.id] = item
          })
          res.data.data.pageInfo.list.forEach(item => {
            item.user = user['U' + item.buyerId]
            item.itemImagePathJson = JSON.parse(item.itemImagePathJson)
            this.orderList.push(item)
          })
          if (res.data.data.pageInfo.nextPage === 0) {
            this.allLoaded = true
          }
        }
        this.$refs.loadmore.onBottomLoaded()
      })
    },
    toDetail (id) {
      this.$router.push({path: '/orderDetail', query: {id}})
    }
  },
  created () {
    this.loadMore()
  }
}
</script>

<style scoped>
  .list{
    /*e9eaec*/
    background-color: #f8f8f9;
    margin-top: 40px;
  }
  .list li{
    background-color: #fff;
    margin: 10px;
    border-radius: 4px;
    box-shadow: 0 0 4px #e9eaec;
    list-style: none;
    padding: 8px 10px;
  }
  .list li.last{
    text-align: center;
    border-bottom: none;
    font-size: 12px;
    color: #bbbec4;
    background-color: #f8f8f9;
    box-shadow: none;
  }
  .top{
    height: 40px;
    overflow: hidden;
    margin-bottom: 8px;
  }
  .top .avatar{
    height: 100%;
    float: left;
    padding: 3px;
    box-sizing: border-box;
    line-height: 40px;
  }
  .avatar img{
    border-radius: 100%;
    overflow: hidden;
    width: 35px;
    height: 35px;
  }
  .time{
    float: right;
    text-align: right;
  }
  .time p:nth-child(1){
    font-size: 12px;
    line-height: 20px;
  }
  .time p:nth-child(2){
    font-size: 14px;
    line-height: 22px;
    color: #ed3f14;
  }
  .goods{
    background-color: #f8f8f9;
    padding: 8px;
    overflow: hidden;
  }
  .goods img{
    display: block;
    float: left;
    margin-right: 8px;
  }
  .bottom{
    font-size: 12px;
    color: #80848f;
    text-align: right;
    margin-top: 10px;
  }
</style>
